import React, { useImperativeHandle } from "react";
import { Form, Input, Radio } from 'antd';

import type { IOuterCreateOrEditProps } from "vendor/components/pro-table-native";
import { getEnv  } from "@/constants";

const layout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 13 },
};

export const CreateOrEdit: IOuterCreateOrEditProps["CreateOrEditContent"] = React.forwardRef(({ values }, actionRef) => {
  const { commonStatus, commonStatusList } = getEnv().globalConfig;
  const [form] = Form.useForm();
  useImperativeHandle(actionRef, () => ({
    getFormData: () => new Promise((resolve, reject) => {
      form.validateFields().then((data) => {
        resolve(data);
      }).catch(() => {
        reject(new Error("请检查参数"));
      });
    })
  }));

  return (
    <Form {...layout}
      initialValues={{
        status: commonStatus.normal,
        ...values
      }}
      form={form}
    >
      <Form.Item
        label="代理商名称"
        name="name"
        rules={[{ required: true, message: '请填写代理商名称!' }]}
      >
        <Input />
      </Form.Item>
      <Form.Item label="公司地址" name="address">
        <Input />
      </Form.Item>
      <Form.Item label="公司联系人" name="linkman">
        <Input />
      </Form.Item>
      <Form.Item label="联系人手机号" name="linkmanPhone">
        <Input />
      </Form.Item>
      <Form.Item label="状态" name="status">
        <Radio.Group options={commonStatusList} />
      </Form.Item>
      <Form.Item label="备注" name="remark">
        <Input.TextArea />
      </Form.Item>
    </Form>
  )
});
